$(document).ready(function () {

    InitBinding();
});


function InitBinding() {


    //SwitchHightlighting($("#HighlightingCSSToUse").val());

    //SwitchHighlighting('ide-msvcpp');

    $(".snippetActionArea").tooltip({ effect: 'slide' });


    $(".collapse img").click(function () {
        $(this).closest(".highlightedSnippetHeader").next(".highlightedSnippet").fadeOut(600);
    });

    $(".expand img").click(function () {
        $(this).closest(".highlightedSnippetHeader").next(".highlightedSnippet").fadeIn(600);
    });


    $(".tweet img").click(function () {
        var snippetElement = $(this).closest(".highlightedSnippetHeader").next(".highlightedSnippet");
        var codeSnippetId = snippetElement.find(".codeSnippetId").val();


        if (!window.location.origin) {
            window.location.origin = window.location.protocol + '//' + window.location.host + '/';
        }

        var tweet = 'https://twitter.com/intent/tweet?source=webclient&text=Currently+viewing+this+code+snippet+' +
            window.location.origin + '/Readonly/Display/' + codeSnippetId;

        // Now, open up the window
        window.open(tweet);
    });


    $(".link img").click(function () {

        var snippetElement = $(this).closest(".highlightedSnippetHeader").next(".highlightedSnippet");
        var codeSnippetId = snippetElement.find(".codeSnippetId").val();


        if (!window.location.origin) {
            window.location.origin = window.location.protocol + '//' + window.location.host + '/';
        }

        showNoButtonsDialog(
                '<p><strong>Snippet link</strong><br/><i>' + window.location.origin +
                '/Readonly/Display/' + codeSnippetId + '</i><br/><br/>' +
                'Copy the link to share it' +
                '</p>', 195, 'Information'
            );
    });

    DetermineMessageToShow();
}


function DetermineMessageToShow() {

    if ($('.snippet').length == 0) {
        $('#noSnippetsMessage').show();
        $('#snippetsMessage').hide();
    }
    else {
        $('#noSnippetsMessage').hide();
        $('#snippetsMessage').show();
    }
}


